

using System.Numerics;

namespace NodeBasedSkillEditor.Model.Node.RT
{
    public class Node_DotProduct_RT : RT_Node
    {
        public RT_SingleValuePort VectorA_RT;

        public RT_SingleValuePort VectorB_RT;

        public RT_SingleValuePort Result_RT;

        public Node_DotProduct_RT(Node_DotProduct sourceData, RT_DAG parentDag) : base(sourceData, parentDag)
        {
            VectorA_RT = new RT_SingleValuePort(EPortIOType.Input, sourceData.VectorA, this);

            VectorB_RT = new RT_SingleValuePort(EPortIOType.Input, sourceData.VectorB, this);

            Result_RT = new RT_SingleValuePort(EPortIOType.Output, sourceData.Result, this);
            Result_RT.OnGetValue = GetResult;
        }

        public AValue GetResult(DAG_Executor executor)
        {
            var vecType = VectorA_RT.SourceValue.ValueType;
            if (vecType == AValue.EValueType.Vector2)
            {
                Vector2 vec2A = VectorA_RT.GetValue(executor).ToVector2().Item2;
                Vector2 vec2B = VectorB_RT.GetValue(executor).ToVector2().Item2;

                float result = Vector2.Dot(vec2A, vec2B);
                Result_RT.SourceValue.SetScalar(result);
            }
            else if (vecType == AValue.EValueType.Vector3)
            {
                Vector3 vec3A = VectorA_RT.GetValue(executor).ToVector3().Item2;
                Vector3 vec3B = VectorB_RT.GetValue(executor).ToVector3().Item2;

                float result = Vector3.Dot(vec3A, vec3B);
                Result_RT.SourceValue.SetScalar(result);
            }
            return Result_RT.SourceValue;
        }
    }
}